package ontoTree.ontoTree;

import javax.swing.tree.DefaultMutableTreeNode;

import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;

/**
 * 
 * @author Ligia
 * 
 */
public class OntologyTreeRenderer extends RelOntoTreeRenderer {

	@Override
	public String setIconType(DefaultMutableTreeNode node) {
		String image = null;
		Object obj = node.getUserObject();
		if (obj instanceof String)
			image = "databaseIcon.JPG";
		else {
			OntResource o = (OntResource) obj;
			if (o.isClass())
				image = "ontClassIcon.jpg";
			if (o.isDatatypeProperty())
				image = "dtPropertyIcon.jpg";
			if (o.isObjectProperty())
				image = "objPropertyIcon.jpg";
		}
		return "images/" + image;
	}

	@Override
	public String setTextType(DefaultMutableTreeNode node) {
		try{
			OntResource ont = (OntResource) node.getUserObject();
			
			if (ont.isProperty()) {
				if (((OntProperty) ont).getRange() != null)

					return " ["
					+ ((OntProperty) ont).getDomain().getLocalName() + "] "+ont.getLocalName() + " ["
							+ ((OntProperty) ont).getRange().getLocalName() + "]";
			}
			return ont.getLocalName();
		}catch(Exception e){
			return node.getUserObject().toString();
		}
		
		

		
	}

};